package mzpd_server

import (
	"context"
	"github.com/zeromicro/go-zero/core/threading"
	"mzpd_server/internal/utils"

	"mzpd_server/internal/svc"
	"mzpd_server/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MZStartMQTTServiceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMZStartMQTTServiceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MZStartMQTTServiceLogic {
	return &MZStartMQTTServiceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MZStartMQTTServiceLogic) MZStartMQTTService(req *types.MZStartMQttServer) (resp *types.MZServiceResponse, err error) {
	// todo: add your logic here and delete this line
	threading.GoSafe(func() {
		boo, err1 := utils.GetMqttServer().Start(l.svcCtx)
		if boo || err1 != nil {
			return
		}
	})
	return &types.MZServiceResponse{
		Code: 200,
		Msg:  "ok",
	}, nil
}
